//
//  ViewController.m
//  UI05_homework_彩虹灯
//
//  Created by 洛洛大人 on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, retain) NSArray *colorArr;

@end

@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [self addllView];
    
    
}


-(void)addllView {
    
    
    self.colorArr =[NSArray arrayWithObjects:[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor],[UIColor greenColor],[UIColor cyanColor],[UIColor blueColor],[UIColor purpleColor], nil];
    
    for (NSInteger i = 0; i < 7; i++ ) {
        
        UIView *llView = [[UIView alloc] initWithFrame:CGRectMake(i * 30, i * 30, self.view.frame.size.width - i * 60, self.view.frame.size.width- i * 60)];
        
        llView.backgroundColor = [self.colorArr objectAtIndex:i];
        
        [self.view addSubview:llView];
        [llView release];
        
    }
    
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(lltimerAction) userInfo:nil repeats:YES];
    
}

-(void)lltimerAction {
    for (UIView *view in self.view.subviews) {
        
        NSInteger index = [self.colorArr indexOfObject:view.backgroundColor];
        
        view.backgroundColor = [self.colorArr objectAtIndex:(index + 1) %7];
    }
    
    
}









@end
